"""
已经存在的API推送配置写入篡改监测以外的任务类型
"""
import arrow

from app.libs.enums import TaskType, TASK_TYPE_CONFIG
from app.db.models.api_token import OutPutConfig


def update_push_config(updated_at):
    try:
        updated_at = arrow.get(updated_at).datetime
    except arrow.parser.ParserError:
        print("更新时间错误")
        exit(-1)
    task_types = [t for t, c in TASK_TYPE_CONFIG.values() if c["is_allow_api_push"] and t != TaskType.change_check.value]
    for a in OutPutConfig.objects.all():
        if (arrow.get(a.updated_at).datetime > updated_at) or a.task_types:
            continue
        a.update(task_types=task_types, updated_at=arrow.utcnow().datetime)
        print(a.id)
